/* JS消息框设计												
* 消息框分三类：		
* 	1	提示信息（Info00X）							
* 	2	错误信息（Err00X）							
* 	3	警告信息（Alert00X）							
* @author lovefuwp.cn 
*/

var keyFlag=false;

if (parent.document.addEventListener) { 
     parent.document.addEventListener( "keyup" ,getKey, false );      
} else if (parent.document.attachEvent) { 
     parent.document.attachEvent( "onkeyup" ,getKey);      
} else { 
     parent.document.onkeyup = getKey; 
} 

if (document.addEventListener) { 
     document.addEventListener( "keyup" ,getKey, false );      
} else if (document.attachEvent) { 
     document.attachEvent( "onkeyup" ,getKey);      
} else { 
     document.onkeyup = getKey; 
}

//1  提示信息
function infoMsg(title,url,mark){
	var type="提示!";
	if(mark==1){
		var infoMsg1="你确定要删除吗？";
		title=url;
		//alert(title);
		openLayer(1,type,title,infoMsg1);
	}
	if(mark==2){
		var infoMsg2="你确定要清空吗？";
		openLayer(1,type,title,infoMsg2);
	}
	if(mark==3){
		var infoMsg3="你确定要保存吗？";
		title=url;
		openLayer(1,type,title,infoMsg3);
	}
	if(mark==4){
		var infoMsg4="你确定要生成吗？";
		title=url;
		openLayer(1,type,title,infoMsg4);
	}
	if(mark==5){
		var infoMsg4="你确定要确认报警信息吗？";
		title=url;
		openLayer(1,type,title,infoMsg4);
	}
	if(mark==6){
		var infoMsg4="你确定要手动出园吗？";
		title=url;		
		//openLayer(6,type,title,infoMsg4);
		openLayer(8,type,title,"alarm");
	}
}



//2  错误信息
function errMsg(){

}

//3  警告信息
function alertMsg(title,txt,mark){
	var type="警告!";
	if(mark==0){		
		openLayer(3,type,title,txt);
	}
	if(mark==1){//   alert1 不能为空
		var alertMsg1="不能为空!";
		openLayer(3,type,title,alertMsg1);
	}
	if(mark==2){//   alert2 不能输入特殊字符		
		var alertMsg2="不能输入特殊字符\"<span style=\"color:#f00;\">"+txt+"</span>\"！";
		openLayer(3,type,title,alertMsg2);
	}
	if(mark==3){//   alert3 字数超过最大限额
		var alertMsg3="不能超过64个字符，请更正！";
		openLayer(3,type,title,alertMsg3);
	}
	if(mark==4){//   alert4 开始时间与结束时间判断
		var alertMsg4="开始时间不能大于结束时间，请更正！";	
		openLayer(3,type,title,alertMsg4);
	}
	if(mark==5){//   alert5 翻页输入框数字与总页数判断
		var alertMsg5="大于了总页数，请重新输入！";
		openLayer(3,type,title,alertMsg5);
	}
	if(mark==6){//   alert6 翻页输入框只能输入数字
		var alertMsg6="为错误的页码！";		
		openLayer(3,type,title,alertMsg6);
	}
	if(mark==7){
		var alertMsg7="请先选择您要删除的数据！";		
		openLayer(3,type,title,alertMsg7);
	}
	if(mark==8){
		var alertMsg8="请先选择您要编辑的数据！";		
		openLayer(3,type,title,alertMsg8);
	}
	if(mark==9){
		var alertMsg9="登录失败请确认用户名和密码是否正确！";		
		openLayer(3,type,title,alertMsg9);
	}
	if(mark==10){
		var alertMsg10="输入不正确，请更正！";		
		openLayer(3,type,title,alertMsg10);
	}
	if(mark==11){
		var alertMsg11="\""+txt+"\"已经被添加！";		
		openLayer(3,type,title,alertMsg11);
	}
	if(mark==12){
		var alertMsg12="必须为数字！";		
		openLayer(3,type,title,alertMsg12);
	}
	if(mark==13){
		var alertMsg13="两次输入的密码不一致，请更正！";		
		openLayer(3,type,title,alertMsg13);
	}
	if(mark==14){
		var alertMsg14="不能超过16个字符，请更正！";		
		openLayer(3,type,title,alertMsg14);
	}
	if(mark==15){
		var alertMsg15="没有选择项可以选择!";		
		openLayer(3,type,title,alertMsg15);
	}
	if(mark==19){
		var alertMsg19="所属权限不能为空，请选择!";		
		openLayer(3,type,title,alertMsg19);
	}
	if(mark==23){
		var alertMsg23="每次只能编辑一条记录!";		
		openLayer(3,type,title,alertMsg23);
	}
	if(mark==24){
		var alertMsg7="请先选择出园的人员！";		
		openLayer(3,type,title,alertMsg7);
	}
	
}

//4  消息框样式
function openLayer(msgType,type,title,msg){
	var arrayPageSize   = getPageSize();//调用getPageSize()函数
	var arrayPageScroll = getPageScroll();//调用getPageScroll()函数
	if (!parent.document.getElementById("popupAddr")){
	
	//创建弹出内容层
		var popupDiv = parent.document.createElement("div");
		
		//给这个元素设置属性与样式
		popupDiv.setAttribute("id","popupAddr");
		popupDiv.style.position = "absolute";
		popupDiv.style.border = "1px solid #ccc";
		popupDiv.style.background = "#fdfdff";
		popupDiv.style.zIndex = 999;				
		
		//创建弹出背景层
		var bodyBack = parent.document.createElement("div");
		bodyBack.setAttribute("id","bodybg");
		bodyBack.style.position = "absolute";
		bodyBack.style.width = "100%";
		bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
		bodyBack.style.zIndex = 98;
		bodyBack.style.top = 0;
		bodyBack.style.left = 0;
		
		bodyBack.style.filter = "alpha(opacity=50)";
		bodyBack.style.opacity = 0.5;
		bodyBack.style.background = "#000";
		
		//创建遮罩的Iframe层
		var bodyIframe = parent.document.createElement("iframe");
		bodyIframe.setAttribute("id","bodyIframe");
		bodyIframe.style.position = "absolute";		
		bodyIframe.style.width = "100%";
		bodyIframe.style.height = "100%";
		bodyIframe.style.zIndex = -1;
		bodyIframe.style.top = 0;
		bodyIframe.style.left = 0;
		bodyIframe.style.scrolling= "no"
		bodyIframe.style.filter = "alpha(opacity=1)";
		bodyIframe.style.opacity = 0.5;
		bodyIframe.style.background = "#000";
		bodyIframe.frameBorder = 0;
		bodyIframe.src="about:blank";
				
		//实现弹出(插入到目标元素之后)
		//var mybody = document.getElementById(objId);
		parent.document.body.appendChild(popupDiv);		
		parent.document.body.appendChild(bodyBack);		
		bodyBack.appendChild(bodyIframe);
			
	}
	
	//显示背景层
	parent.document.getElementById("bodybg").style.display = "";
	//bodyIframe
	var aa=parent.document.getElementById("bodyIframe");
	aa.innerHTML;
	
	//显示内容层
	if(!parent.document.getElementById("popupAddr")) return false;
	var popObj=parent.document.getElementById("popupAddr");
	//alert(popObj.innerHTML);
	if(!parent.document.getElementById("msgHeader")){
	
		var msgHeader=parent.document.createElement("div");
		msgHeader.setAttribute("id","msgHeader");
		popObj.appendChild(msgHeader);
		
		var headTxt=parent.document.createElement("span");
		headTxt.setAttribute("id","headTxt");
		msgHeader.appendChild(headTxt);
						
		var msgImg=parent.document.createElement("img");
		msgImg.setAttribute("id","msgImg");
		msgImg.setAttribute("src","/SCMDB/images/msgClose.gif");
		msgImg.setAttribute("title","关闭");
		msgHeader.appendChild(msgImg);	
		
		msgButton=parent.document.createElement("div");
		msgButton.setAttribute("id","msgButton");
		msgButton.style.width = "100%";
		popObj.appendChild(msgButton);
		
		msgDetail=parent.document.createElement("p");
		msgDetail.setAttribute("id","msgDetail");
		msgDetail.style.position = "relative";
		msgDetail.style.width = "235px";
		msgDetail.style.lineHeight = "25px";
		
		msgDetail.style.zIndex = 9999;
		
		msgButton.appendChild(msgDetail);
		
		var msgInput=parent.document.createElement("input");
		msgInput.setAttribute("id","input1");
		msgInput.setAttribute("type","button");
		msgInput.setAttribute("value","确定");
		
		msgButton.appendChild(msgInput);
				
		var span1=parent.document.createElement("span");
		span1.setAttribute("id","span1");
		msgButton.appendChild(span1);
		
		var msgInput2=parent.document.createElement("input");
		msgInput2.setAttribute("id","input2");
		msgInput2.setAttribute("type","button");
		msgInput2.setAttribute("value","取消");
		//span1.appendChild(msgInput2);
		
	}	
	if(!parent.document.getElementById("msgImg")) return false;
	if(!parent.document.getElementById("input1")) return false;	
	if(!parent.document.getElementById("msgDetail")) return false;
	var msgImgOn=parent.document.getElementById("msgImg");
	msgImgOn.onclick=function(){closeLayer();}
	window.setTimeout("parent.document.getElementById(\"input1\").focus();", 50); 
	
	var inputOn=parent.document.getElementById("input1");
	inputOn.onclick=function(){closeLayer();}
	
	if(msgType==1){
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="系统提示";
		
		var inputOn=parent.document.getElementById("input1");
		inputOn.onclick=function(){okLayer(title);}
		
		var spanSet=parent.document.getElementById("span1");			
		spanSet.style.display="inline";
		
		spanSet.innerHTML="<input type=\"button\" value=\"取消\" id=\"input2\" />";
		var inputOn2=parent.document.getElementById("input2");
		inputOn2.onclick=function(){closeLayer();}
		
		var msgTxt=parent.document.getElementById("msgDetail");	
		msgTxt.style.background="url(/SCMDB/images/msginfo.gif) no-repeat 0 5px";
		msgTxt.innerHTML = ""+msg+"";
		keyFlag=true;
	}
	if(msgType==6){
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="系统提示";
		
		var inputOn=parent.document.getElementById("input1");
		inputOn.onclick=function(){saveLayer(title);}
		
		var spanSet=parent.document.getElementById("span1");			
		spanSet.style.display="inline";
		
		spanSet.innerHTML="<input type=\"button\" value=\"取消\" id=\"input2\" />";
		var inputOn2=parent.document.getElementById("input2");
		inputOn2.onclick=function(){closeLayer();}
		
		var msgTxt=parent.document.getElementById("msgDetail");	
		msgTxt.style.background="url(/SCMDB/images/msginfo.gif) no-repeat 0 5px";
		msgTxt.innerHTML = ""+msg+"";
		keyFlag=true;
	}
	if(msgType==2){
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="系统提示";
		
		var inputOn=parent.document.getElementById("input1");
		
		inputOn.onclick=function(){saveLayer(title);}
		//var msgImgOn=parent.document.getElementById("msgImg");
		parent.document.getElementById("msgImg").onclick=function(){saveLayer(title);}
		
		var spanSet=parent.document.getElementById("span1");			
		spanSet.innerHTML="";
		
		var msgTxt=parent.document.getElementById("msgDetail");	
		msgTxt.style.background="url(/SCMDB/images/msgSuccess.gif) no-repeat 0 5px";
		msgTxt.innerHTML = ""+msg+"";
		keyFlag=true;
	}
	
	if(msgType==3){
		
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="系统警告";
		
		var inputOn=parent.document.getElementById("input1");
		inputOn.onclick=function(){closeLayer();}		
		var spanSet=parent.document.getElementById("span1");			
		spanSet.innerHTML="";
		
		var inputOn2=parent.document.getElementById("input2");
		
		var msgTxt=parent.document.getElementById("msgDetail");	
		//msgTxt.setAttribute("class","msgAlertImg");
		msgTxt.style.background="url(/SCMDB/images/notice.gif) no-repeat 0 5px";
		msgTxt.innerHTML = ""+title+""+msg+"";
		keyFlag=true;
		
	}
	//设置区域范围
	if(msgType==5){
		
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="设置路径";
		
		var inputOn=parent.document.getElementById("input1");
		inputOn.onclick=function(){closeLayer1(msg);}	
		
		var msgImgOn=parent.document.getElementById("msgImg");
		msgImgOn.onclick=function(){closeLayer2(msg);}
			
		var spanSet=parent.document.getElementById("span1");			
		spanSet.innerHTML="";
		
		var inputOn2=parent.document.getElementById("input2");
		
		var msgTxt=parent.document.getElementById("msgDetail");			
		msgTxt.style.width="710px";
		msgTxt.style.height="470px";
		msgTxt.style.border="1px solid #aaa";
		msgTxt.style.margin="10px 15px"; 
		msgTxt.style.padding="0px"; 
		msgTxt.style.position="relative";
		msgTxt.style.overflow="auto";		
		//创建区域选择模块
		//msgTxt.innerHTML="1234";
		msgTxt.innerHTML="<input type=\"hidden\" value=\""+pathArray[0].readerId+","+pathArray[0].readerX+","+pathArray[0].readerY+"\" id=\"readerNo_1\" /><input type=\"hidden\" value=\""+pathArray[1].readerId+","+pathArray[1].readerX+","+pathArray[1].readerY+"\" id=\"readerNo_2\" /><input type=\"hidden\" value=\""+msg+"\" id=\"pathsInput\" /><iframe name=\"drawArea\" style=\"position:absolute;top:0px;right:0px;bottom:0px;left:0px;margin:0px;padding:0px;width:100%;height:100%;*width:710px;\" src=\"/SCMDB/reader/pathSet.jsp\" frameborder=\"0\" scrolling=\"auto\" ></iframe>";	
		keyFlag=true;
		
	}
	//手动出园处理专用
	if(msgType==8){		
		var headTxtSet=parent.document.getElementById("headTxt");
		headTxtSet.innerHTML="提示！";		
		var msgImgOn=parent.document.getElementById("msgImg");
		msgImgOn.onclick=function(){closeLayer();}		
		var inputOn=parent.document.getElementById("input1");		
		var spanSet=parent.document.getElementById("span1");			
		spanSet.style.display="";		
		spanSet.innerHTML="<input type=\"button\" value=\"取消\" id=\"input2\" />";
		var inputOn2=parent.document.getElementById("input2");
		inputOn2.onclick=function(){closeLayer();}		
		var inputOn2=parent.document.getElementById("input2");
		var msgTxt=parent.document.getElementById("msgDetail");
		msgTxt.style.width="400px";
		msgTxt.style.height="80px";
		msgTxt.style.border="0px solid #aaa";
		msgTxt.style.margin="10px 15px"; 
		msgTxt.style.padding="0px"; 
		msgTxt.style.position="relative";
		msgTxt.style.overflow="auto";
		msgTxt.style.background="";
		//创建手动出园时间信息输入框
		var almContentHTML="";		 
		inputOn.onclick=function(){closePopLay("",6,title);}				
		almContentHTML="<form action="+title+" method=\"post\" target=\"main\">";
		almContentHTML=almContentHTML+" &nbsp;&nbsp;请输入出园时间<label style=\"color:#999;\">( 2010-01-01 )</label>：<br /><input name=\"operatingTime \" id=\"operatingTime\" readonly=\"true\" onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" style=\"border:1px solid #999; background:#fff;width:180px;height:18px;cursor:pointer;\"  title=\"输入出园时间\" /></form>";		
		msgTxt.innerHTML=almContentHTML;
		keyFlag=true;	
		
		
	}	
	//alert(popObj.innerHTML);
	popObj.style.display = "";

	//让弹出层在页面中垂直左右居中(统一)
	popObj.style.width  = "300px";	
	popObj.style.top  = arrayPageScroll[1] + (arrayPageSize[3] - 35 - 100) / 2 + 'px';
	popObj.style.left = (arrayPageSize[0] - 20 - 300) / 2 + 'px';
	if(msgType==5){
		popObj.style.width  = "740px";
		popObj.style.height = "550px";
		popObj.style.top  = arrayPageScroll[1] + (arrayPageSize[3] - 35-520) / 2 + 'px';
		popObj.style.left = (arrayPageSize[0] - 20 - 740) / 2 + 'px';
	}else if(msgType==8||msgType==9){
		popObj.style.width  = "430px";
		popObj.style.height = "160px";
		popObj.style.top  = arrayPageScroll[1] + (arrayPageSize[3] - 35-130) / 2 + 'px';
		popObj.style.left = (arrayPageSize[0] - 20 - 430) / 2 + 'px';
	}		
	return false;
	
}
 
//插入后面
function insertAfter(newElement,targetElement){//插入
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement){
		parent.appendChild(newElement);
	}
	else{
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}
//获取滚动条的高度
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (parent.document.documentElement && parent.document.documentElement.scrollTop){
		yScroll = parent.document.documentElement.scrollTop;
	} else if (parent.document.body) {
		yScroll = parent.document.body.scrollTop;
	}
	
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
//获取页面实际大小
function getPageSize(){
	var xScroll,yScroll;
	
	if (window.innerHeight && window.scrollMaxY){
		xScroll = parent.document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (parent.document.body.scrollHeight > parent.document.body.offsetHeight){
		xScroll = parent.document.body.scrollWidth;
		yScroll = parent.document.body.scrollHeight;
	} else {
		xScroll = parent.document.body.offsetWidth;
		yScroll = parent.document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;
	//var pageHeight,pageWidth; 
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (parent.document.documentElement && parent.document.documentElement.clientHeight) {
		windowWidth = parent.document.documentElement.clientWidth;
		windowHeight = parent.document.documentElement.clientHeight;
	} else if (parent.document.body) {
		windowWidth = parent.document.body.clientWidth;
		windowHeight = parent.document.body.clientHeight;
	}
	
	var pageWidth,pageHeight
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
//关闭弹出层function closeLayer1(id){//路径专用保存函数
	var beginRId= parent.document.getElementById("readerNo_1").value.split(",")[0].replace(/^[^\d]*(\d+)[^\d]*$/, "$1");
	var endRId= parent.document.getElementById("readerNo_2").value.split(",")[0].replace(/^[^\d]*(\d+)[^\d]*$/, "$1");		
	pathUpdate(beginRId,endRId,parent.document.getElementById("pathsInput").value);
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));
	$("pathSet").value="设置路径请先点击此按钮！";
	$("pathHidden").focus();
	pathSetFlag=false;
	pathArray=[];	
	keyFlag=false;
	return false;
}
function closeLayer2(id){//路径按图片关闭按钮时，强制把输入焦点设置到Number上	
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));		
	$("pathSet").value="设置路径请先点击此按钮！";
	$("pathHidden").focus();
	pathSetFlag=false;
	pathArray=[];
	keyFlag=false;
	return false;
}
function closeLayer(){
	//parent.document.getElementById("popupAddr").style.display = "none";
	//parent.document.getElementById("bodybg").style.display = "none";
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));	
	keyFlag=false;
	return false;
}
function okLayer(url){
	//alert(url);
	//parent.document.getElementById("popupAddr").style.display = "none";
	//parent.document.getElementById("bodybg").style.display = "none";
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));	
	document.forms[0].action=url;
	document.forms[0].submit();
	return false;
}
function saveLayer(url){
	//parent.document.getElementById("popupAddr").style.display = "none";
	//parent.document.getElementById("bodybg").style.display = "none";
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));	
	document.location.href=url;
	return false;
}
function closePopLay(id,type,url){
	//alert(url);	
	if(type==6){
		if(document.getElementById("operatingTime").value==""){
			alert("请选择出园日期！");
			return false;
		}
		else
		{
		url=url+"&operatingTime="+document.getElementById("operatingTime").value;
		parent.document.forms[0].action=url;
		parent.document.forms[0].submit();}	
	}
	parent.document.body.removeChild(parent.document.getElementById("popupAddr"));
	parent.document.body.removeChild(parent.document.getElementById("bodybg"));	
	keyFlag=false;
	return false;
}
function getKey(e){ 
	    e = e || window.event; 
	    var keycode = e.which ? e.which : e.keyCode;
	    if (keycode == 27){ //按ESC键关闭提示框 
	    	if(keyFlag==true){
	    		closeLayer();
	    	}
	    } 
	 }